POV-Ray : Newsgroups : povray.general : A little trig help : Re: A little trig help Server Time
4 Aug 2024 14:21:26 EDT (-0400)
  Re: A little trig help  
From: Retsam
Date: 26 Apr 2003 01:30:05
Message: <web.3eaa18733bdd876d34dff4bb0@news.povray.org>
Alan Walkington wrote:
>Ok .. I want to distribute 'things' equaly spaced around a streched disk.
>
>I can do it on the plain disk easily enough:
>            #local R = 1.75;
>            #local V =.4;
>            #local Count = 0;
>            #local Max = 4;
>
>            #while (Count < Max)
>                #local Theta = Count * (360/Max);
>                #local X = -R * cos(radians(Theta));
>                #local Z = -R * sin(radians(Theta));
>                #local Count = Count + 1;
>
>                sphere{<0,0,0>.15 translate <X,V,Z>}
>            #end
>
>but I really want an oval? .. elipse? .. created by stretching the disk:
>
>cylinder {<0,0,0><0,.5,0> 2 scale <1.5,1,1>}
>
>I can place the 'decorations' equally spaced by degrees on a plain disk, but
>what I want is to place them equally spaced by distance on a stretched disk.
>
>Any suggestions appreciated
>


I know this code looks bizarre, but it works pretty good.  Try this inside
your loop:

                #local Theta = radians(Count * (360/Max));
                #local Theta = Theta + 0.1*sin(2*Theta);
                #local X = -1.5*R * cos(Theta);
                #local Z = -R * sin(Theta);
                #local Count = Count + 1;

                sphere{<0,0,0>.15 translate <X,V,Z> pigment {color rgb 1}}

Now, if you want an explanation, I can't offer a very good one, but I'll
try.

Basically, you have to compensate for the fact that near Theta=0 and
Theta=pi, the points are too close together.

Near Theta=0, adding 0.1*sin(2*Theta) is pretty close to adding 0.2*Theta.
This means that near Theta=0, Theta is really 1.2*Theta, so the points will
be spread out.

Near Theta=pi/2, adding 0.1*sin(2*Theta) is really close to subtracting
0.2*(Theta-pi/2).  So, near Theta=pi/2, Theta is really 0.8*Theta + some
constant.

The effect is, Theta increases at a rate of between 0.8 and 1.2, instead of
at a constant rate of 1.  1.2/0.8 is 1.5, which is how skewed your ellipse
is.  So the points should be equally spaced near Theta =0,pi/2, pi, and
3/2*pi.  In between, there will be some variance, but it shouldn't be too
bad.


Post a reply to this message

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.